{*Smarty*}

{literal}
<script language=javascript>
<!--
    function selectAll(flag)
    {
        var f = document.forms['sibling_form'];
        for(i=0; i<f.elements.length; i++){
            if(f.elements[i].name == "chbx[]"){
                f.elements[i].checked = flag
            }
        }// for
    }
    function isblank(field) {
        var field = '{/literal}{$insert_list_str}{literal}';
        var mega = '{/literal}{$res_folder_str}{literal}';
        
        var f = document.forms['sibling_form'];
        var chbx_flag = 0;
        var count_chbx = 0;
        for(i=0; i<f.elements.length; i++){
            if(f.elements[i].name == "chbx[]"){
                count_chbx ++;
                if(f.elements[i].checked){
                    chbx_flag ++;
                    
                }
            }
        }
        
        var a_name = "";
        var a_action = "";
        var str_inner = "";
        switch(document.getElementById('sibling_action').value){
            case "swap":
                if(chbx_flag<2){
                    alert("Please check at least two items.");
                    a_name = -1;
                }else{
                    a_name = "Swap Items";
                    a_action = "swap";
                }
                break;
            // ==================  insert_after ==================
            case "insert_after":
                if(chbx_flag<1){
                    alert("Please check at least one item.");
                    a_name = -1;
                }else{
                    /// we get params
                    in_params = field.split("||");
                    var i_p = new Array();
                    for(i= 0; i <in_params.length;i++){
                        i_p[i] = in_params[i].split("|");
                    }
                    
                    a_name = "Insert Selected After";
                    a_action = "insert_after";
                        str_inner =str_inner+ "<select name='sibling_count'>";
                        for(i=1; i<count_chbx+1 ; i++){
                            if(i_p[i-1])
                            str_inner += "<option value='"+ i_p[i-1][1]+"'>"+ i_p[i-1][1]+" - "+i_p[i-1][2] +"</option>";
                        }
                        str_inner +="</select>&nbsp;";
                }
                break;
            // ==================  insert_before ==================
            case "insert_before":
                if(chbx_flag<1){
                    alert("Please check at least one item.");
                    a_name = -1;
                }else{
                    /// we get params
                    in_params = field.split("||");
                    var i_p = new Array();
                    for(i= 0; i <in_params.length;i++){
                        i_p[i] = in_params[i].split("|");
                    }
                    
                    a_name = "Insert Before After";
                    a_action = "insert_before";
                        str_inner =str_inner+ "<select name='sibling_count'>";
                        for(i=1; i<count_chbx+1 ; i++){
                            str_inner += "<option value='"+ i_p[i-1][1]+"'>"+ i_p[i-1][1]+" - "+i_p[i-1][2] +"</option>";
                        }
                        str_inner +="</select>&nbsp;";
                }
                break;
            // ==================  insert_before ==================
            case "sibling_delete":
                if(chbx_flag<1){
                    alert("Please check at least one item.");
                    a_name = -1;
                }else{
                    a_name = "Delete Items";
                    a_action = "sibling_delete";
                }
                break;
            // ==================  move_to_folder ==================
            case "move_to_folder":
                if(chbx_flag<1){
                    alert("Please check at least one item.");
                    a_name = -1;
                }else{
                    a_name = "Move to Folder";
                    a_action = "move_to_folder";
                        /// we get params
                        //alert(mega);
                        in_params = mega.split("||");
                        var i_p = new Array();
                        for(i= 0; i <in_params.length;i++){
                            i_p[i] = in_params[i].split("|");
                        }
                        //alert(i_p.length+  " " +count_chbx ); 
                        str_inner =str_inner+ "<select name='sibling_count'>";
                        for(i=1; i<in_params.length +1 ; i++){
                            str_inner += "<option value='"+ i_p[i-1][0]+"'>"+ i_p[i-1][1]+"</option>";
                        }
                        str_inner +="</select>&nbsp;";
                }
                break;
            // ==================  -1  ==================
            
            case "-1":
                a_name="-1";
        }
        
        if(a_name != "-1")
         str_inner += "<input type='button' value='"+a_name+"' class='button' onclick='getConfirm()'/> <input type='hidden' name='action' value='"+a_action+"'/>";
        else{ 
            str_inner = "";
            document.getElementById('sibling_action').selectedIndex = 0;
        }
        document.getElementById('sibling_div').innerHTML= str_inner;
    }
    
    function getConfirm()
    {
        var mes = window.confirm("Click OK to process action. Click Cancel to cancel action.");
        if (mes) {
            frm = document.forms['sibling_form'].submit();
        } else  window.alert("You cancel action!");
    }   
// -->
</script>
{/literal}
<div>
<table>
    <tr>
        <td>
            <a href="" onclick="selectAll(true);return false;" >Select&nbsp;All</a>&nbsp;/&nbsp;<a href="" onclick="selectAll(false);return false;">Unselect&nbsp;All</a>
        </td>
    </tr>
    <tr>
        <td>
        <select name="sibling_action" id="sibling_action" onchange="isblank()">
            <option value="-1">{$select_text}</option>
            {foreach from=$action_list item=item key=key}
            <option value="{$key}">{$item}</option>
            {foreachelse}
            <option value="-1">Empty Action List</option>
            {/foreach}
        </select>
        </td>
        <td>
            <div id="sibling_div" style="sborder:1px solid blue;"></div>
        </td>
    </tr>
</table>
</div>